package com.ai.web.weixin.processor;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ai.web.service.WxUserService;
import com.ai.web.weixin.message.request.ReqBaseMessage;
import com.tiny.persistence.domain.WxUser;
import com.tiny.persistence.repository.WxUserRepo;

@Service(value = "unfollowMsgProcessor")
public class UnFollowMsgProcessor implements IMessageProcessor {

	private static Logger logger = Logger.getLogger(UnFollowMsgProcessor.class);

	@Autowired
	private WxUserRepo wxUserRepo;
	@Autowired
	private WxUserService wxUserService;
	
	public String process(ReqBaseMessage bm) {

		logger.info("[UnFollow Processor] " + bm.toString());
		WxUser user = wxUserService.getByOpenId(bm.getFromUserName());
		wxUserRepo.delete(user.getId());
		if(logger.isDebugEnabled()) {
			logger.debug("微信用户取消关注,系统删除微信用户成功,openId="+bm.getFromUserName());
		}
		return "";
	}

}
